package 剑指Offer._1120;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/7/16 20:33
 * 剪绳子
 * 算法：数学  动态规划
 * a = b + c
 * max(b * c, b * dp[a - b])
 */
public class _14I {

    public int cuttingRope(int n) {
        int[] dp = new int[n + 1];
        dp[0] = dp[1] = 0;
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i - 1; j++) dp[i] = Math.max(dp[i], Math.max(j * (i - j), j * dp[i - j]));
        }
        return dp[n];
    }

}
